package vn.edu.saigontech.ncms.model.system;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Enumerated;

import vn.edu.saigontech.ncms.model.enumeration.Currency;

@Embeddable
@SuppressWarnings("serial")
public class Money implements Serializable {
	
	private Double amount;
	private Currency currency;
	
	public Money() {}
	
	public Money(Double amount, Currency currency) {
		this.amount = amount;
		this.currency = currency;
	}

	@Column(name = "amount")
	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	@Enumerated
	@Column(name = "currency")
	public Currency getCurrency() {
		return currency;
	}

	public void setCurrency(Currency currency) {
		this.currency = currency;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == this) return true;
		if(obj == null) return false;
		if(!obj.getClass().equals(this.getClass())) return false;
		Money that = (Money)obj;
		return that.amount == this.amount && that.currency.equals(this.currency);
	}
	
	@Override
	public int hashCode() {
		return Double.valueOf(this.amount).hashCode();
	}
	
	@Override
	public String toString() {
		return "Money[" + this.amount + " " + this.currency + "]";
	}
}